package com.ehotting.edsta.mqbd.monitor.web.config;

import com.ehotting.mqbd.api.MQDBConstants;
import com.ehotting.edsta.mqbd.api.enums.SysModuleEnum;
import com.ehotting.mqbd.core.helper.MQStringHelper;
import com.ehotting.mqbd.core.logger.MQSendLogger;
import com.ehotting.mqbd.core.manager.MsgStateManager;
import com.ehotting.mqbd.core.manager.SolverStateManager;

import com.ehotting.mqbd.api.bean.MqApplicationContext;
import com.ehotting.mqbd.core.service.MQService;
import com.ehotting.mqbd.core.config.MqbdCorePropertyConfig;
import com.ehotting.mqbd.core.helper.IPHelper;
import com.ehotting.mqbd.core.mq.MessageProducer;
import com.ehotting.mqbd.core.sync.MqSyncFutureMapHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
@DependsOn("mqbdCorePropertyConfig")
public class MonitorWebConfig {

    @Autowired
    private IPHelper ipHelper;

    @Bean(name ="messageProducer",initMethod = "start",destroyMethod = "shutdown")
    public MessageProducer concurrencyMessageProducer(MqbdCorePropertyConfig mqbdCorePropertyConfig)  {
        MqApplicationContext mqApplicationContext = new MqApplicationContext();
        mqApplicationContext.setModule("SCHEDULE");
        mqApplicationContext.setLocalHost(ipHelper.getIp());
        mqApplicationContext.setConsumerHost("");
        MessageProducer messageProducer = new MessageProducer(
                mqbdCorePropertyConfig.getProducer(),
                MQStringHelper.createProducerGroup(mqApplicationContext));
        return messageProducer;
    }

    @Bean(name="mqService")
    public MQService mqService(MessageProducer messageProducer,MqSyncFutureMapHelper mqSyncFutureMapHelper,
                               MQSendLogger mqSendLogger){
        return new MQService(messageProducer,mqSyncFutureMapHelper,mqSendLogger);
    }

}